﻿<!DOCTYPE html>
<html>
<head>
    <title>JS Exam Exercise 1</title>
    <script>
        function Solve(args) {
            var N = parseInt(args[0]);
            var numArr = [];

            var maxSum = -2000001;

            for (var idx = 1; idx <= N; idx++)
            {
                numArr.push(parseInt(args[idx]))
            }

            if (1 == N)
            {
                return numArr[0];
            }

            for (var startIdx = 0; startIdx < N - 1; startIdx++)
            {
                for (var endIdx = startIdx; endIdx < N; endIdx++)
                {
                    var localSum = numArr[startIdx];
                    for(var idx = startIdx + 1; idx <= endIdx; idx++)
                    {
                        localSum += numArr[idx];
                    }

                    if (localSum > maxSum)
                    {
                        maxSum = localSum;
                    }
                }
            }

            return maxSum;
        }

        function execute() {
            var args = [];
            args[0] = "9";
            args[1] = "-9";
            args[2] = "-8";
            args[3] = "-8";
            args[4] = "-7";
            args[5] = "-6";
            args[6] = "-5";
            args[7] = "-1";
            args[8] = "-7";
            args[9] = "-6";


            console.log(Solve(args));
        }
    </script>
</head>
<body onload="execute()">
        
</body>
</html>
